using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class DynamicFilledImage : MonoBehaviour
{
	public Image image;

	private Sequence fillSq;

	public float FillAmount
	{
		get
		{
			return image.fillAmount;
		}
		set
		{
			image.fillAmount = value;
		}
	}

	private void Awake()
	{
		image = GetComponent<Image>();
	}

	public void SetFill(float fill)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, 1f));
	}

	public void SetFill(float fill, bool linear)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, 1f).SetEase(Ease.InCubic));
	}

	public void SetFill(float fill, Action callback)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, 1f + 1f * fill).OnComplete(delegate
		{
			callback();
		}));
	}

	public void SetFill(float fill, float time)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, time).SetEase(Ease.InCubic));
	}

	public void SetFill(float fill, float time, bool linear)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, time).SetEase(Ease.Linear));
	}

	public void SetFill(float fill, float time, Action callback)
	{
		if (image == null)
		{
			image = GetComponent<Image>();
		}
		fillSq?.Kill();
		fillSq = DOTween.Sequence();
		fillSq.Append(DOTween.To(() => image.fillAmount, delegate(float x)
		{
			image.fillAmount = x;
		}, fill, time).SetEase(Ease.Linear).OnComplete(delegate
		{
			callback();
		}));
	}

	public void KillFill()
	{
		fillSq?.Kill();
	}
}
